﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Pacocation
{
    class Player
    {
        Texture2D player;
        int posicaox;
        public Rectangle rectPlayer;
        KeyboardState kState;

        public Player(ContentManager Content)
        {
            player = Content.Load<Texture2D>("bat");
            rectPlayer = new Rectangle (480, 550, player.Width, player.Height);
            posicaox = 5;
            kState = new KeyboardState();
           
        }

        public void Update(GameTime gameTime)
        {
            Input();
            rectPlayer = new Rectangle(rectPlayer.X - posicaox, rectPlayer.Y , player.Width, player.Height);
            posicaox = 0;

        }

        private void Input()
        {
            kState = Keyboard.GetState();

            if (kState.IsKeyDown(Keys.Left) && rectPlayer.X >= 240)
            {
                posicaox = 5;
            }

            if (kState.IsKeyDown(Keys.Right) && rectPlayer.X <= (800 - (player.Width+5)))
            {
              posicaox = -5;
           }
            
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(player, rectPlayer, Color.White);
            spriteBatch.End();
        }
    }
}
